//package com.plian.system.service.pm.listedcompany.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.cache.UserCache;
//import com.plian.system.common.status.CheckStatus;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.constant.yth.YthConstant;
//import com.plian.system.dto.pm.listedcompany.EarningsReportDTO;
//import com.plian.system.entity.pm.listedcompany.BaseExpenditureItems;
//import com.plian.system.entity.pm.listedcompany.ExpenditureItemDetail;
//import com.plian.system.entity.sys.ApprovalMessage;
//import com.plian.system.entity.sys.Org;
//import com.plian.system.mapper.pm.listedcompany.BaseExpenditureItemsMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.properties.GzwProperties;
//import com.plian.system.service.pm.listedcompany.IBaseExpenditureItemsService;
//import com.plian.system.service.pm.listedcompany.IExpenditureItemDetailService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.sys.message.IApprovalMessageService;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.service.sys.user.ISysUserService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.pm.listedcompany.BaseExpenditureItemsVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import com.plian.system.vo.yth.YthResult;
//import com.plian.system.wrapper.pm.listedcompany.BaseExpenditureItemsWrapper;
//import lombok.AllArgsConstructor;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.RequestBody;
//
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.INVESTMENT_EXECUTION;
//import static com.plian.system.constant.sys.ApprovalMessageTypeConstant.KT_TYPE;
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//import static com.plian.system.constant.sys.FormTypeConstant.QM_EXPENDITURE_ITEM;
//import static com.plian.system.constant.sys.FormTypeConstant.QM_EXPENDITURE_ITEM_GZW;
//
///**
// * @Description: TODO
// * @Author: Take-off
// * @Date: 2023/2/27 11:19 AM
// * @Param
// * @return
// * @Version: 1.0
// **/
//@Service
//@AllArgsConstructor
//public class BaseExpenditureItemsServiceImpl extends BaseServiceImpl<BaseExpenditureItemsMapper, BaseExpenditureItems> implements IBaseExpenditureItemsService, BaseFlowService {
//
//    private final IExpenditureItemDetailService expenditureItemDetailService;
//
//    private final BaseExpenditureItemsWrapper baseExpenditureItemsWrapper;
//
//    private final FormWorkflowService formWorkflowService;
//
//    private final IFormCodeService formCodeService;
//
//    private final IOrgService orgService;
//
//    private ISysUserService userService;
//
//    private final static Integer IS_MONITOR = 1;
//
//    private final static String IS_DEL = "1";
//
//    private final GzwProperties gzwProperties;
//
//    private IApprovalMessageService approvalMessageService;
//    @Override
//    public boolean saveOrUpdate(BaseExpenditureItems baseExpenditureItems) {
//        boolean flag = false;
//        if (!Optional.ofNullable(baseExpenditureItems.getStatus()).isPresent()) {
//            baseExpenditureItems.setStatus(FormStatusConstant.UNREVIEWED);
//        }
//        if (baseExpenditureItems.getStatus().equals(FormStatusConstant.REJECT)) {
//            baseExpenditureItems.setStatus(FormStatusConstant.UNREVIEWED);
//        }
//        if (!Optional.ofNullable(baseExpenditureItems.getId()).isPresent()) {
//            baseExpenditureItems.setCode(formCodeService.getCode(Integer.parseInt(baseExpenditureItems.getFormType())));
//        }
//        boolean result = super.saveOrUpdate(baseExpenditureItems);
//        return result;
//    }
//
//    @Override
//    public boolean deleteLogic(List<Long> ids) {
//        for (Long id : ids) {
//            BaseExpenditureItems baseExpenditureItems = getById(id);
//            if (baseExpenditureItems == null) {
//                return false;
//            } else if (baseExpenditureItems.getStatus() != null &&
//                    (baseExpenditureItems.getStatus() != FormStatusConstant.STASH && baseExpenditureItems.getStatus() != FormStatusConstant.UNREVIEWED)) {
//                return false;
//            }
//            formWorkflowService.deleteProcessInstance(String.valueOf(id));
//        }
//        boolean result = super.deleteLogic(ids);
//        if (result){
//            expenditureItemDetailService.deleteByParentId(ids);
//        }
//        return result;
//    }
//
//    @Override
//    @Transactional(rollbackFor=RuntimeException.class)
//    public boolean submit(BaseExpenditureItems baseExpenditureItems) {
//        boolean result = saveOrUpdate(baseExpenditureItems);
//        if (result){
//            List<ExpenditureItemDetail> expenditureItemDetails = baseExpenditureItems.getExpenditureItemDetails();
//            if (CollectionUtil.isNotEmpty(expenditureItemDetails)){
//                for (ExpenditureItemDetail expenditureItemDetail : expenditureItemDetails){
//                    if (expenditureItemDetail.getId() != null &&
//                            Optional.ofNullable(expenditureItemDetail.getIsDeleted()).isPresent() && expenditureItemDetail.getIsDeleted().intValue() == 1) {
//                        expenditureItemDetailService.removeById(expenditureItemDetail.getId());
//                    }else {
//                        expenditureItemDetail.setBaseId(baseExpenditureItems.getId());
//                        //企业填写的塞入所属企业
//                        if (baseExpenditureItems.getFormType().equals(String.valueOf(FormTypeConstant.QM_EXPENDITURE_ITEM))){
//                            expenditureItemDetail.setOrgId(baseExpenditureItems.getFillingOrgId());
//                        }
//                        expenditureItemDetailService.saveOrUpdate(expenditureItemDetail);
//                    }
//                }
//            }
//        }
//        return result;
//    }
//
//    @Override
//    public BaseExpenditureItemsVO getDetailObj(BaseExpenditureItems baseExpenditureItems) {
//        BaseExpenditureItems detail = getOne(Condition.getQueryWrapper(baseExpenditureItems));
//        BaseExpenditureItemsVO baseExpenditureItemsVO = baseExpenditureItemsWrapper.entityToVO(detail);
//        //子项
//        List<ExpenditureItemDetail> details = expenditureItemDetailService.list(new LambdaQueryWrapper<ExpenditureItemDetail>().eq(ExpenditureItemDetail::getBaseId, baseExpenditureItemsVO.getId()));
//        if (CollectionUtil.isNotEmpty(details)){
//            expenditureItemDetailService.setFiles(details);
//        }
//        baseExpenditureItemsVO.setExpenditureItemDetails(details);
//
//        return baseExpenditureItemsVO;
//    }
//
//    @Override
//    public BigDecimal getActualExpenditure(BaseExpenditureItems baseExpenditureItems){
//        baseExpenditureItems.setFormType(String.valueOf(FormTypeConstant.QM_EXPENDITURE_ITEM_GZW));
//        baseExpenditureItems.setStatus(3);
//        BaseExpenditureItems detail = getOne(Condition.getQueryWrapper(baseExpenditureItems));
//        if (Optional.ofNullable(detail).isPresent()){
//            //子项
//            List<ExpenditureItemDetail> details = expenditureItemDetailService.list(new LambdaQueryWrapper<ExpenditureItemDetail>().eq(ExpenditureItemDetail::getBaseId, detail.getId()));
//            if (CollectionUtil.isNotEmpty(details)){
//                //小结的拟安排支出加起来
//                BigDecimal total = details.stream().filter(m -> Optional.ofNullable(m.getIsSummary()).isPresent() && m.getIsSummary() == 1)
//                        .map(ExpenditureItemDetail::getProposedExpenditure).reduce(BigDecimal.ZERO, BigDecimal::add);
//                return total;
//            }
//        }
//        return null;
//    }
//
//    @Override
//    public ListResult<BaseExpenditureItemsVO> list(@RequestBody Query query) {
//        List<SearchEntity> entityList = query.getSearch();
//        if (query.getAscs()==null&&query.getDescs()==null){
//            query.setDescs("create_time");
//        }
//        QueryWrapper<BaseExpenditureItems> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new BaseExpenditureItems()), entityList
//        );
//        //只查看自己填写的单据
//        queryWrapper.eq("filling_org_id",TokenUtil.getTokenOrgId());
//
//        IPage<BaseExpenditureItems> pages = page(Condition.getPage(query), queryWrapper);
//        List<BaseExpenditureItemsVO> baseExpenditureItemsVOS = baseExpenditureItemsWrapper.entityToVO(pages.getRecords());
//        ListResult<BaseExpenditureItemsVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(baseExpenditureItemsVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }
//
//    @Override
//    public ListResult<ExpenditureItemDetail> getExpenditureDetails(BaseExpenditureItems baseExpenditureItem){
//        List<ExpenditureItemDetail> expenditureItemDetails = new ArrayList<>();
//        String year = baseExpenditureItem.getExpenditureYear();
//        if (Optional.ofNullable(year).isPresent()){
//            //获取13家企业
//            List<Org> units = getUnit();
//            //指定年份主表
//            List<BaseExpenditureItems> baseExpenditureItems = list(new LambdaQueryWrapper<BaseExpenditureItems>().eq(BaseExpenditureItems::getExpenditureYear, year).eq(BaseExpenditureItems::getStatus, 3));
//            if (CollectionUtil.isNotEmpty(baseExpenditureItems)){
//                //获取子集
//                List<ExpenditureItemDetail> itemDetails = expenditureItemDetailService.list(new LambdaQueryWrapper<ExpenditureItemDetail>().in(ExpenditureItemDetail::getBaseId,
//                        baseExpenditureItems.stream().map(BaseExpenditureItems::getId).collect(Collectors.toList())));
//                int index = 1;
//                for (Org org:units){
//                    List<BaseExpenditureItems> items = baseExpenditureItems.stream().filter(m -> org.getId().equals(m.getFillingOrgId())).collect(Collectors.toList());
//                    if (CollectionUtil.isNotEmpty(items)){
//                        BaseExpenditureItems expenditureItems = items.get(0);
//                        List<ExpenditureItemDetail> details = itemDetails.stream().filter(m -> expenditureItems.getId().equals(m.getBaseId()) && Optional.ofNullable(m.getIndexNum()).isPresent())
//                                .sorted(Comparator.comparing(ExpenditureItemDetail::getIndexNum)).collect(Collectors.toList());
//                        if (CollectionUtil.isNotEmpty(details)){
//                            //增加附件
//                            expenditureItemDetailService.setFiles(details);
//                            ExpenditureItemDetail detailsByOrg = getDetailsByOrg(details,org,index);
//                            setIndex(details,index);
//                            index++;
//                            expenditureItemDetails.add(detailsByOrg);
//                            expenditureItemDetails.addAll(details);
//                        }
//                    }
//                }
//            }
//        }
//
//        ListResult<ExpenditureItemDetail> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(expenditureItemDetails);
//        listResult.setTotal(expenditureItemDetails.size());
//        return listResult;
//    }
//
//    @Override
//    public ReportReturnVO report(EarningsReportDTO dto){
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//
//        List<String> orgIds = dto.getOrgIds();
//        String year = dto.getYear();
//        List<ExpenditureItemDetail> itemDetails = new ArrayList<>();
//        //获取13家企业
//        List<Org> units = getUnit();
//
//        //主表
//        List<BaseExpenditureItems> thisYearItems = list(new LambdaQueryWrapper<BaseExpenditureItems>().eq(BaseExpenditureItems::getStatus, 3).in(BaseExpenditureItems::getFillingOrgId, orgIds)
//                .eq(BaseExpenditureItems::getExpenditureYear, year));
//        //详情
//        List<ExpenditureItemDetail> thisYearItemsDetails = getItemDetail(thisYearItems);
//
//        if (CollectionUtil.isNotEmpty(thisYearItemsDetails)) {
//            for (Org org : units) {
//                String orgId = org.getId();
//                int index = 1;
//                List<ExpenditureItemDetail> details = thisYearItemsDetails.stream().filter(m -> orgId.equals(m.getOrgId())).sorted(Comparator.comparing(ExpenditureItemDetail::getIndexNum)).collect(Collectors.toList());
//                if (CollectionUtil.isNotEmpty(details)){
//                    ExpenditureItemDetail detailsByOrg = getDetailsByOrg(details, org);
//                    itemDetails.add(detailsByOrg);
//                    for (ExpenditureItemDetail detail: details) {
//                        detail.setExpenditureName(index +"."+detail.getExpenditureName());
//                        //转换支出类型
//                        if (Optional.ofNullable(detail.getExpenditureType()).isPresent()){
//                            detail.setExpenditureTypeString(detail.getExpenditureType() == 1 ? "补贴" : "资本金注入");
//                        }
//                        if (Optional.ofNullable(detail.getGzwExpenditureType()).isPresent()){
//                            detail.setGzwExpenditureTypeString(detail.getGzwExpenditureType() == 1 ? "补贴" : "资本金注入");
//                        }
//
//                        index++;
//                        itemDetails.add(detail);
//                    }
//                }
//            }
//        }
//        ReportVO reportVO = new ReportVO();
//        //企业申报数
//        List<HeaderVO> itemHead = new ArrayList<>();
//        itemHead.add(HeaderVO.builder().key("expenditureTypeString").title("支出类型").build());
//        itemHead.add(HeaderVO.builder().key("subtotal").title("合计（万元）").build());
//        itemHead.add(HeaderVO.builder().key("capitalExpenditure").title("资本性支出（万元）").build());
//        itemHead.add(HeaderVO.builder().key("expense").title("费用性支出（万元）").build());
//        itemHead.add(HeaderVO.builder().key("otherExpense").title("其他支出（万元）").build());
//
//        //市国资委拟安排项目
//        List<HeaderVO> gzwHead = new ArrayList<>();
//        gzwHead.add(HeaderVO.builder().key("proposedExpenditure").title("拟安排支出（万元）").build());
//        gzwHead.add(HeaderVO.builder().key("gzwExpenditureTypeString").title("支出类型").build());
//        gzwHead.add(HeaderVO.builder().key("gzwRemarks").title("备注").build());
//
//        reportVO
//                .addHeader(HeaderVO.builder().key("expenditureName").title("企业名称").build())
//                .addHeader(HeaderVO.builder().children(itemHead).title("企业申报数").build())
//                .addHeader(HeaderVO.builder().children(gzwHead).title("市国资委拟安排项目").build())
//        ;
//        reportVO.setData(itemDetails);
//        reportReturnVO.setGrids(reportVO);
//        return reportReturnVO;
//    }
//
//    /**
//     * @Description: //TODO 获取详情
//     * @Author: Take-off
//     * @Date: 10:49 PM 2023/3/6
//     * @Param: [yearItems]
//     * @return: java.util.List<com.plian.system.entity.pm.listedcompany.ExpenditureItemDetail>
//     **/
//    private List<ExpenditureItemDetail> getItemDetail(List<BaseExpenditureItems> yearItems){
//        List<ExpenditureItemDetail> yearExecuteDetails = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(yearItems)){
//            List<BaseExpenditureItems> gzwYearItems = yearItems.stream().filter(item -> item.getFormType().equals(String.valueOf(FormTypeConstant.QM_EXPENDITURE_ITEM_GZW))).collect(Collectors.toList());
//            if (CollectionUtil.isNotEmpty(gzwYearItems)){
//                yearExecuteDetails = expenditureItemDetailService.list(new LambdaQueryWrapper<ExpenditureItemDetail>().in(ExpenditureItemDetail::getBaseId, gzwYearItems.stream().map(BaseExpenditureItems::getId).collect(Collectors.toList())));
//            }else {
//                yearExecuteDetails = expenditureItemDetailService.list(new LambdaQueryWrapper<ExpenditureItemDetail>().in(ExpenditureItemDetail::getBaseId, yearItems.stream().map(BaseExpenditureItems::getId).collect(Collectors.toList())));
//            }
//        }
//        return yearExecuteDetails;
//    }
//
//    /**
//     * @Description: //TODO 生成组织的小计-企业
//     * @Author: Take-off
//     * @Date: 2:25 PM 2023/2/27
//     * @Param: [details, org, index]
//     * @return: com.plian.system.entity.pm.listedcompany.ExpenditureItemDetail
//     **/
//    private ExpenditureItemDetail getDetailsByOrg(List<ExpenditureItemDetail> details,Org org,int index){
//        ExpenditureItemDetail expenditureItemDetail = new ExpenditureItemDetail();
//        expenditureItemDetail.setIndexNum(index+"");
//        expenditureItemDetail.setExpenditureName(org.getName());
//
//        List<BigDecimal> subtotals = details.stream().map(ExpenditureItemDetail::getSubtotal).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setSubtotal(BigDecimalUtil.addBigDecimals(subtotals));
//
//        List<BigDecimal> capitalExpenditures = details.stream().map(ExpenditureItemDetail::getCapitalExpenditure).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setCapitalExpenditure(BigDecimalUtil.addBigDecimals(capitalExpenditures));
//
//        List<BigDecimal> expenses = details.stream().map(ExpenditureItemDetail::getExpense).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setExpense(BigDecimalUtil.addBigDecimals(expenses));
//
//        List<BigDecimal> otherExpenses = details.stream().map(ExpenditureItemDetail::getOtherExpense).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setOtherExpense(BigDecimalUtil.addBigDecimals(otherExpenses));
//        expenditureItemDetail.setIsSummary(1);
//        return expenditureItemDetail;
//    }
//
//    /**
//     * @Description: //TODO 生成组织的小计-国资报表用
//     * @Author: Take-off
//     * @Date: 2:25 PM 2023/2/27
//     * @Param: [details, org, index]
//     * @return: com.plian.system.entity.pm.listedcompany.ExpenditureItemDetail
//     **/
//    private ExpenditureItemDetail getDetailsByOrg(List<ExpenditureItemDetail> details,Org org){
//        ExpenditureItemDetail expenditureItemDetail = new ExpenditureItemDetail();
//        expenditureItemDetail.setExpenditureName(org.getName());
//
//        List<BigDecimal> subtotals = details.stream().map(ExpenditureItemDetail::getSubtotal).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setSubtotal(BigDecimalUtil.addBigDecimals(subtotals));
//
//        List<BigDecimal> capitalExpenditures = details.stream().map(ExpenditureItemDetail::getCapitalExpenditure).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setCapitalExpenditure(BigDecimalUtil.addBigDecimals(capitalExpenditures));
//
//        List<BigDecimal> expenses = details.stream().map(ExpenditureItemDetail::getExpense).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setExpense(BigDecimalUtil.addBigDecimals(expenses));
//
//        List<BigDecimal> otherExpenses = details.stream().map(ExpenditureItemDetail::getOtherExpense).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setOtherExpense(BigDecimalUtil.addBigDecimals(otherExpenses));
//
//        List<BigDecimal> proposedExpenditures = details.stream().map(ExpenditureItemDetail::getProposedExpenditure).filter(m -> Optional.ofNullable(m).isPresent()).collect(Collectors.toList());
//        expenditureItemDetail.setProposedExpenditure(BigDecimalUtil.addBigDecimals(proposedExpenditures));
//
//        expenditureItemDetail.setIsSummary(1);
//        return expenditureItemDetail;
//    }
//
//    /**
//     * @Description: //TODO 构成新序号
//     * @Author: Take-off
//     * @Date: 2:25 PM 2023/2/27
//     * @Param: [details, index]
//     * @return: void
//     **/
//    private void setIndex(List<ExpenditureItemDetail> details,int index){
//        for (ExpenditureItemDetail detail:details){
//            detail.setIndexNum(index +"."+detail.getIndexNum());
//            detail.setId(null);
//            detail.setBaseId(null);
//            detail.setIsSummary(0);
//        }
//    }
//
//    /**
//     * @Description: //TODO 获取排序好的13家
//     * @Author: Take-off
//     * @Date: 1:55 PM 2023/2/27
//     * @Param: []
//     * @return: java.util.List<com.plian.system.entity.sys.Org>
//     **/
//    private List<Org> getUnit(){
//        return orgService.list(new LambdaQueryWrapper<Org>()
//                .ne(Org::getIsDel, IS_DEL)
//                .eq(Org::getIsMonitor, IS_MONITOR)
//                .eq(Org::getParentId, gzwProperties.getReportId())
//                .orderByAsc(Org::getOrderNum));
//    }
//
//    @Override
//    public HashMap<String,Object> commit(String id) {
//        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW, null);
//
//        //将需要提交的流程变量返回，用于工作流侧
//        return new HashMap<String,Object>();
//    }
//
//    @Override
//    public Boolean finish(String id) {
//        return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH,"审批通过");
//    }
//
//    @Override
//    public Boolean reject(String id, int formState, String comment) {
//        return handleStatus(Long.valueOf(id), formState, comment);
//    }
//
//    @Override
//    public List<PageData> findByIds(List<String> formIds) {
//        LambdaQueryWrapper<BaseExpenditureItems> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.in(BaseExpenditureItems::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//        List<BaseExpenditureItems> baseExpenditureItems = list(queryWrapper);
//        List<BaseExpenditureItemsVO> baseExpenditureItemsVOS = baseExpenditureItemsWrapper.entityToVO(baseExpenditureItems);
//        List<PageData> pageDataList = new ArrayList<>();
//        try{
//            if (CollectionUtil.isNotEmpty(baseExpenditureItemsVOS)){
//                for (BaseExpenditureItemsVO vo : baseExpenditureItemsVOS){
//                    PageData pd = new PageData();
//                    pd.put("id", vo.getId());
//                    pd.put("UNITNAME", vo.getFillingOrgName());
//                    pd.put("APPLICANTNAME", vo.getCreateUserName());
//                    pd.put("applicantId", vo.getCreateUser());
//                    pd.put("applyOrganizationId", vo.getCreateCompanyId());
//                    pd.put("formType", vo.getFormType());
//                    pd.put("orgName", vo.getFillingOrgName());
//                    pageDataList.add(pd);
//                }
//            }
//
//            return pageDataList;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//        return pageDataList;
//    }
//
//    /**
//     * QM_EXPENDITURE_ITEM_GZW
//     * @return
//     */
//    @Override
//    public List<Integer> getFormType() {
//        return Arrays.asList(QM_EXPENDITURE_ITEM, QM_EXPENDITURE_ITEM_GZW);
//    }
//
//    @Override
//    public void goBackToStash(String formId) {
//        handleStatus(Long.valueOf(formId), UNREVIEWED, null);
//    }
//
//    /**
//     * 统一处理状态机事件方法
//     *
//     * @param id          主键
//     * @param updateStatus  更新状态
//     * @return boolean
//     */
//    private Boolean handleStatus(Long id, int updateStatus,String comment) {
//        try {
//            BaseExpenditureItems baseExpenditureItems = getById(id);
//            /**
//             * 设置审批人和审批时间
//             */
//            if (updateStatus == FormStatusConstant.FINISH){
//                baseExpenditureItems.setApprovedUser(TokenUtil.getTokenUserId());
//                Date now = DateUtil.now();
//                baseExpenditureItems.setApprovedTime(now);
//            }
//            if (StringUtil.isNotBlank(baseExpenditureItems.getDataSource()) &&StringUtil.isNotBlank(baseExpenditureItems.getDataSourceId())){
//                if (updateStatus == FormStatusConstant.FINISH || updateStatus == FormStatusConstant.REJECT){
//                    ApprovalMessage approvalMessage = new ApprovalMessage();
//                    approvalMessage.setDataSourceId(baseExpenditureItems.getDataSourceId());
//                    approvalMessage.setType(INVESTMENT_EXECUTION);
//                    approvalMessage.setOpinion(comment);
//                    approvalMessage.setIsApprove(updateStatus == FormStatusConstant.FINISH ? 2 : 1);
//                    approvalMessage.setIsSend(1);
//                    approvalMessage.setDataSourceType(KT_TYPE);
//                    if (baseExpenditureItems.getDataSource().equals(YthConstant.DATA_NINGBO)) {
//                        approvalMessage.setDataSourceType(YthConstant.DATA_NINGBO);
//                        approvalMessage.setFilingUserName(UserCache.userIdToName(TokenUtil.getTokenUserId()));
//                        approvalMessage.setFormType(Integer.parseInt(baseExpenditureItems.getFormType()));
//                        approvalMessage.setFilingCode(baseExpenditureItems.getCode());
//                    }
//                    approvalMessageService.save(approvalMessage);
//                }
//            }
//
//            baseExpenditureItems.setStatus(updateStatus);
//            updateById(baseExpenditureItems);
//            return true;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return false;
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public String saveBaseExpenditureItems(String data){
//        YthResult ythResult = new YthResult();
//        //成功的id集合
//        List<String> successIds = new ArrayList<>();
//        //失败的id集合
//        List<String> failIds = new ArrayList<>();
//        //失败的原因
//        List<String> failReasons = new ArrayList<>();
//        //将json字符串转换成list
//        List<BaseExpenditureItems> dataList = JSON.parseArray(data, BaseExpenditureItems.class);
//        if (CollectionUtil.isNotEmpty(dataList)){
//            Map<String, String> orgSourceMap = orgService.getSourceId();
//            Map<String, String> userSourceMap = userService.getSourceId();
//            //根据datasourceIds 查询出所有的数据
//            List<BaseExpenditureItems> list = list(new LambdaQueryWrapper<BaseExpenditureItems>().in(BaseExpenditureItems::getDataSourceId, dataList.stream().map(BaseExpenditureItems::getDataSourceId).toArray()));
//            if (CollectionUtil.isNotEmpty(list)){
//                //删除子集
//                List<Long> ids = list.stream().map(BaseExpenditureItems::getId).collect(Collectors.toList());
//                expenditureItemDetailService.remove(new LambdaQueryWrapper<ExpenditureItemDetail>().in(ExpenditureItemDetail::getBaseId, ids));
//            }
//            //如果数据库中有数据，就更新，没有就新增
//            for (BaseExpenditureItems entity:dataList){
//                transfer(entity,orgSourceMap,userSourceMap);
//                //id重复略过
//                if (CollectionUtil.isNotEmpty(list)){
//                    List<String> olIds = list.stream().map(BaseExpenditureItems::getDataSourceId).collect(Collectors.toList());
//                    String dataSourceId = entity.getDataSourceId();
//                    //判断数据库中是否有数据
//                    if (olIds.contains(dataSourceId)){
//                        for (BaseExpenditureItems oldEntity:list){
//                            if (dataSourceId.equals(oldEntity.getDataSourceId())){
//                                //判断status是否为0，如果是0，就更新，不是0，就不更新
//                                if (CheckStatus.checkCode(oldEntity.getStatus())){
//                                    successIds.add(dataSourceId);
//                                    entity.setId(oldEntity.getId());
//                                    entity.setDataSource(YthConstant.DATA_NINGBO);
//                                    entity.setFormType(String.valueOf(FormTypeConstant.QM_EXPENDITURE_ITEM));
//                                    submit(entity);
//                                    list.remove(oldEntity);
//                                    break;
//                                }else {
//                                    failIds.add(dataSourceId);
//                                    failReasons.add("dataSourceId:"+dataSourceId+"数据已提交且已经在流程中，无法更新");
//                                    break;
//                                }
//                            }
//                        }
//                    }else {
//                        //如果数据库中没有数据，就新增
//                        entity.setDataSource(YthConstant.DATA_NINGBO);
//                        submit(entity);
//                        successIds.add(entity.getDataSourceId());
//                    }
//                }else {
//                    //如果数据库中没有数据，就新增
//                    entity.setDataSource(YthConstant.DATA_NINGBO);
//                    submit(entity);
//                    successIds.add(entity.getDataSourceId());
//                }
//            }
//        } else {
//            failReasons.add("数据为空");
//        }
//        ythResult.setSuccessIds(successIds);
//        ythResult.setFailIds(failIds);
//        ythResult.setFailReason(StringUtils.join(failReasons, ";"));
//        //ythResult转换成json字符串
//        return JSON.toJSONString(ythResult);
//    }
//
//    private void transfer(BaseExpenditureItems entity, Map<String, String> orgSourceMap, Map<String, String> userSourceMap){
//        Optional.ofNullable(entity.getFillingOrgId()).ifPresent(m ->
//                {
//                    String orgId = orgSourceMap.get(m);
//                    if (StringUtil.isNotBlank(orgId)){
//                        entity.setCreateCompanyId(orgId);
//                        entity.setFillingOrgId(orgId);
//                    }
//                }
//        );
//        Optional.ofNullable(entity.getCreateUser()).ifPresent(m ->
//                {
//                    String userId = userSourceMap.get(m);
//                    if (StringUtil.isNotBlank(userId)){
//                        entity.setCreateUser(userId);
//                    }
//                }
//        );
//    }
//
//}
